﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Christoc.Modules.discourseSSOdnn
{
    public class ssoEngine
    {


        public static string getHash(string payload, string ssoSecret)
        {
            var encoding = new System.Text.UTF8Encoding();
            byte[] keyBytes = encoding.GetBytes(ssoSecret);

            System.Security.Cryptography.HMACSHA256 hasher = new System.Security.Cryptography.HMACSHA256(keyBytes);

            byte[] bytes = encoding.GetBytes(payload);
            byte[] hash = hasher.ComputeHash(bytes);

            string ret = string.Empty;
            foreach (byte x in hash)
                ret += String.Format("{0:x2}", x);
            return ret;
        }   
    }
}